package use_tooljar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ab.task.AbTaskItem;
import com.ab.task.AbTaskListener;
import com.ab.view.listener.AbOnListViewListener;
import com.ab.view.pullview.AbPullListView;
import com.example.com.skills_utf8.R;
import com.utils.Utils1;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class USETOOLJAR_MainActivity extends Activity{

	
	AbPullListView  listview;
	Adapter adapter;
	List<String> listdata = new ArrayList<String>();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.usertooljar_main);
		
		
		for(int i =0; i< 10; i++){
			listdata.add(""+i);
			
		}
		
		
		adapter = new Adapter(listdata);
		
		listview = (AbPullListView)findViewById(R.id.mListView);
		listview.setAdapter(adapter);
		listview.setPullLoadEnable(true);
		listview.setPullRefreshEnable(true);
		listview.setAbOnListViewListener(new AbOnListViewListener() {

			@Override
			public void onRefresh() {

		//		mAbTaskQueue.execute(item1);
				
				new Thread(){
					@Override
					public void run() {
						// TODO Auto-generated method stub
						super.run();
						
						Utils1.WaitMs(2000);
				//		listview.stopRefresh(); //only the original thread that created a view hierarchy can touch tis view.
						
						///* OK
						runOnUiThread( new Runnable() {
							
							@Override
							public void run() {
								// TODO Auto-generated method stub
								listview.stopRefresh();
							}
						});
						//*/
						
					}
				}.start();
				
				
			}

			@Override
			public void onLoadMore() {
		//		mAbTaskQueue.execute(item2);
				
				new Thread(){
					@Override
					public void run() {
						// TODO Auto-generated method stub
						super.run();
						
						Utils1.WaitMs(2000);
						
				//		listview.stopLoadMore();
						
						///* OK
						runOnUiThread( new Runnable() {
							
							@Override
							public void run() {
								// TODO Auto-generated method stub
								listview.stopLoadMore();
							}
						});
						//*/
						
					}
				}.start();
			}

		});
		
		
		
		
		
		
		/*
		// 定义两种查询的事件
		final AbTaskItem item1 = new AbTaskItem();
		item1.listener = new AbTaskListener() {

			@Override
			public void update() {
				

//				list.clear();
//
//				if (newList != null && newList.size() > 0) {
//					list.addAll(newList);
//					myListViewAdapter.notifyDataSetChanged();
//					newList.clear();
//				}
				listview.stopRefresh();
			}

			@Override
			public void get() {
					
				for(int i =10; i<20;i++){
					listdata.add(""+i);
				}
				
				
			};
			
			
		};
*/
				
				
		
		
		
	}
	
	
	class Adapter extends BaseAdapter
	{

		List<String> mListdata;
		LayoutInflater layout_inflater;
		
		Adapter(List<String> listdata){
			mListdata = listdata;
			
			layout_inflater = USETOOLJAR_MainActivity.this.getLayoutInflater();
			
		}
		
		
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mListdata.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return mListdata.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			
			View view =layout_inflater.inflate(R.layout.adapter_shops_comment, null);
			
			
			return view;
		}
	
	
	}
	
	
	
}
